package com.zhang.zhangapp.view.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lzy.imagepicker.bean.ImageItem;
import com.zhang.zhangapp.R;
import com.zhang.zhangapp.application.MApplication;
import com.zhang.zhangapp.utils.DensityUtils;
import com.zhang.zhangapp.utils.ScreenUtils;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2018/4/21.
 */

public class UserCommentImageAdapter extends BaseAdapter {

    List<ImageItem> fileList;
    Context context;

    public UserCommentImageAdapter(List<ImageItem> fileList, Context context) {
        this.fileList = fileList;
        this.context = context;
    }

    @Override
    public int getCount() {
        if (fileList == null) {
            return 0;
        } else if (fileList.size() >= 5) {
            return 5;
        }
        return fileList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_shop_characteristic, null);
            x.view().inject(viewHolder, view);
            view.setTag(viewHolder);
        } else viewHolder = (ViewHolder) view.getTag();
        String url = fileList.get(position).path;
        viewHolder.imageView.setImageURI(Uri.parse(url));
        viewHolder.textView.setVisibility(View.GONE);
        if (position == fileList.size() - 1) {
            viewHolder.imageView.setImageResource(R.mipmap.add_image);
        }
        return view;
    }

    class ViewHolder {
        @ViewInject(R.id.item_shop_characteristic_img)
        ImageView imageView;
        @ViewInject(R.id.item_shop_characteristic_name)
        TextView textView;
    }
}
